#include<stdio.h>
#include<conio.h>

#define max 100
/*
Owais Lone
Roll no: 25133
Class: SE-II

Bitwise Operations
*/


void div();
void check();
void convert();
void main()
{

int num,a,sw,res;
char d;
do
{
clrscr();
printf("1:Bitwise Division\n2:Check for Odd/Even\n3:Decimal to Binary\n4:Exit\n>");
scanf("%d",&sw);
switch(sw)
{
    case 1:
	clrscr();
	div();
	break;

    case 2:
	clrscr();
	check();
	break;

    case 3:
	convert();
	break;


    case 4:
    exit();
    break;

}   clrscr();
    printf("Continue?...Y/N");
    flushall();
    d=getche();


}while(d=='y'||d=='Y');
}


void div()
{
int num,a,res;
	printf("Enter any Number\n");
	scanf("%d",&num);
	printf("\nDivide %d by (power of 2) ",num);
	scanf("%d",&a);
	res=num>>a;
	clrscr();
	printf("\nAns= %d ",res);
	getch();

}
void check()
{
int num,res;
    printf("Enter any number");
    scanf("%d",&num);
    res=num&1;
    if(res==0)
    {
    printf("%d is Even",num);
    }
    else
    {
    printf("%d is Odd",num);
    }
    getch();
}

void convert()
{
int i,num,a[max],m;

printf("Enter the number\n");
scanf("%d",&num);
i=0;
for(;num!=0;)
    {
     a[i]=num%2;
     i++;
     num=num/2;
    }
i--;
m=i;
clrscr();
printf("Binary= ");
for(i=m;i>=0;i--)
    {
     printf("%d",a[i]);

    }

    getch();
}